package top.toptimus.dto.order.orderSync;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import top.toptimus.util.DateTimeUtil;
import top.toptimus.util.ValueUtil;

import java.util.Date;

/**
 * 订单基本信息表DTO
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class OrderSynDTO {
    private String ORDER_ID;
    private String ORDER_NO;
    private String ORDER_TYPE_CD;
    private int SHOP_ID;
    private String SHOP_NAME;
    private String CUSTOM_ORDER_NO;
    private String CUSTOM_NAME;
    private String CUSTOM_MAKE_SHIRT;
    private String TRANSIT_GROUP;
    private String COUNTRY;
    private int SLEEVE_FLAG;
    private int CUSTOMER_ID;
    private String CUSTOMER_NAME;
    private String FACTORY_ID;
    private int STYLE_ID;
    private int REF_ORDER_ID;
    private String SPECIAL_ORDER;
    private String TRYON_ORDER;
    private int FIT_STYLE_SIZE;
    private int TAILOR_ID;
    private String SHIPPING_DESTINATION;
    private Date ORDER_DATE;
    private Date PAYMENT_DATE;
    private Date PAYMENT_CONFIRM_DATE;
    private Date ORDER_ACCEPT_DATE;
    private Date ORDER_PRO_START_DATE;
    private Date ORDER_PRO_END_DATE;
    private Date ORDER_PACK_DATE;
    private Date ORDER_SHIPMENTS_DATE;
    private Date TARGET_DATE;
    private Date REAL_DATE;
    private String ORDER_STATUS_CD;
    private String ORDER_PRODUCE_STATUS_CD;
    private String ORDER_QC34;
    private String ORDER_QC35;
    private String ORDER_QC36;
    private String ORDER_QC37;
    private Double ORDER_NUMBER;
    private Double ORDER_MATERIAL_COST;
    private Double ORDER_DESIGN_COST;
    private Double ORDER_PROCESS_COST;
    private Double ORDER_PACK_COST;
    private Double ORDER_EXPRESS_COST;
    private Double ORDER_SELL_ACCOUNT;
    private Double ORDER_OTHER_COST;
    private String URGENT_CD;
    private int MATERIAL_SOURCE;
    private String REMARKS;
    private int DELETE_FLAG;
    private String VERSION;
    private Date CREATE_DATE;
    private Date UPDATE_DATE;
    private int CREATE_USER;
    private int UPDATE_USER;
    private String SEL_KBN;
    private int PRINT_FLAG;

    private boolean ERPOrderExisted;  //  erp内的订单是否存在

    public OrderSynDTO(
            String ORDER_ID,
            String ORDER_NO,
            String ORDER_TYPE_CD,
            String SHOP_ID,
            String SHOP_NAME,
            String CUSTOM_ORDER_NO,
            String CUSTOM_NAME,
            String CUSTOM_MAKE_SHIRT,
            String TRANSIT_GROUP,
            String COUNTRY,
            String SLEEVE_FLAG,
            String CUSTOMER_ID,
            String CUSTOMER_NAME,
            String FACTORY_ID,
            String STYLE_ID,
            String REF_ORDER_ID,
            String SPECIAL_ORDER,
            String TRYON_ORDER,
            String FIT_STYLE_SIZE,
            String TAILOR_ID,
            String SHIPPING_DESTINATION,
            String ORDER_DATE,
            String PAYMENT_DATE,
            String PAYMENT_CONFIRM_DATE,
            String ORDER_ACCEPT_DATE,
            String ORDER_PRO_START_DATE,
            String ORDER_PRO_END_DATE,
            String ORDER_PACK_DATE,
            String ORDER_SHIPMENTS_DATE,
            String TARGET_DATE,
            String REAL_DATE,
            String ORDER_STATUS_CD,
            String ORDER_PRODUCE_STATUS_CD,
            String ORDER_QC34,
            String ORDER_QC35,
            String ORDER_QC36,
            String ORDER_QC37,
            String ORDER_NUMBER,
            String ORDER_MATERIAL_COST,
            String ORDER_DESIGN_COST,
            String ORDER_PROCESS_COST,
            String ORDER_PACK_COST,
            String ORDER_EXPRESS_COST,
            String ORDER_SELL_ACCOUNT,
            String ORDER_OTHER_COST,
            String URGENT_CD,
            String MATERIAL_SOURCE,
            String REMARKS,
            String DELETE_FLAG,
            String VERSION,
            String CREATE_DATE,
            String UPDATE_DATE,
            String CREATE_USER,
            String UPDATE_USER,
            String SEL_KBN,
            String PRINT_FLAG
    ) {
        this.ORDER_ID = ORDER_ID;
        this.ORDER_NO = ORDER_NO;
        this.ORDER_TYPE_CD = ORDER_TYPE_CD;
        this.SHOP_ID = ValueUtil.IntNullValue(SHOP_ID);
        this.SHOP_NAME = SHOP_NAME;
        this.CUSTOM_ORDER_NO = CUSTOM_ORDER_NO;
        this.CUSTOM_NAME = CUSTOM_NAME;
        this.CUSTOM_MAKE_SHIRT = CUSTOM_MAKE_SHIRT;
        this.TRANSIT_GROUP = TRANSIT_GROUP;
        this.COUNTRY = COUNTRY;
        this.SLEEVE_FLAG = ValueUtil.IntNullValue(SLEEVE_FLAG);
        this.CUSTOMER_ID = ValueUtil.IntNullValue(CUSTOMER_ID);
        this.CUSTOMER_NAME = CUSTOMER_NAME;
        this.FACTORY_ID = FACTORY_ID;
        this.STYLE_ID = ValueUtil.IntNullValue(STYLE_ID);
        this.REF_ORDER_ID = ValueUtil.IntNullValue(REF_ORDER_ID);
        this.SPECIAL_ORDER = SPECIAL_ORDER;
        this.TRYON_ORDER = TRYON_ORDER;
        this.FIT_STYLE_SIZE = ValueUtil.IntNullValue(FIT_STYLE_SIZE);
        this.TAILOR_ID = ValueUtil.IntNullValue(TAILOR_ID);
        this.SHIPPING_DESTINATION = SHIPPING_DESTINATION;
        this.ORDER_DATE = DateTimeUtil.strToDateLong(ORDER_DATE);
        this.PAYMENT_DATE = DateTimeUtil.strToDateLong(PAYMENT_DATE);
        this.PAYMENT_CONFIRM_DATE = DateTimeUtil.strToDateLong(PAYMENT_CONFIRM_DATE);
        this.ORDER_ACCEPT_DATE = DateTimeUtil.strToDateLong(ORDER_ACCEPT_DATE);
        this.ORDER_PRO_START_DATE = DateTimeUtil.strToDateLong(ORDER_PRO_START_DATE);
        this.ORDER_PRO_END_DATE = DateTimeUtil.strToDateLong(ORDER_PRO_END_DATE);
        this.ORDER_PACK_DATE = DateTimeUtil.strToDateLong(ORDER_PACK_DATE);
        this.ORDER_SHIPMENTS_DATE = DateTimeUtil.strToDateLong(ORDER_SHIPMENTS_DATE);
        this.TARGET_DATE = DateTimeUtil.strToDateLong(TARGET_DATE);
        this.REAL_DATE = DateTimeUtil.strToDateLong(REAL_DATE);
        this.ORDER_STATUS_CD = ORDER_STATUS_CD;
        this.ORDER_PRODUCE_STATUS_CD = ORDER_PRODUCE_STATUS_CD;
        this.ORDER_QC34 = ORDER_QC34;
        this.ORDER_QC35 = ORDER_QC35;
        this.ORDER_QC36 = ORDER_QC36;
        this.ORDER_QC37 = ORDER_QC37;
        this.ORDER_NUMBER = ValueUtil.DoubleNullValue(ORDER_NUMBER);
        this.ORDER_MATERIAL_COST = ValueUtil.DoubleNullValue(ORDER_MATERIAL_COST);
        this.ORDER_DESIGN_COST = ValueUtil.DoubleNullValue(ORDER_DESIGN_COST);
        this.ORDER_PROCESS_COST = ValueUtil.DoubleNullValue(ORDER_PROCESS_COST);
        this.ORDER_PACK_COST = ValueUtil.DoubleNullValue(ORDER_PACK_COST);
        this.ORDER_EXPRESS_COST = ValueUtil.DoubleNullValue(ORDER_EXPRESS_COST);
        this.ORDER_SELL_ACCOUNT = ValueUtil.DoubleNullValue(ORDER_SELL_ACCOUNT);
        this.ORDER_OTHER_COST = ValueUtil.DoubleNullValue(ORDER_OTHER_COST);
        this.URGENT_CD = URGENT_CD;
        this.MATERIAL_SOURCE = ValueUtil.IntNullValue(MATERIAL_SOURCE);
        this.REMARKS = REMARKS;
        this.DELETE_FLAG = ValueUtil.IntNullValue(DELETE_FLAG);
        this.VERSION = VERSION;
        this.CREATE_DATE = DateTimeUtil.strToDateLong(CREATE_DATE);
        this.UPDATE_DATE = DateTimeUtil.strToDateLong(UPDATE_DATE);
        this.CREATE_USER = ValueUtil.IntNullValue(CREATE_USER);
        this.UPDATE_USER = ValueUtil.IntNullValue(UPDATE_USER);
        this.SEL_KBN = SEL_KBN;
        this.PRINT_FLAG = ValueUtil.IntNullValue(PRINT_FLAG);
    }

    public OrderSynDTO buildOrderExist(boolean existed) {
        this.ERPOrderExisted = existed;
        return this;
    }

    public String insertSQL(String aliyunMaxStyleId) {
        return "INSERT INTO o_order_p (\n" +
                "   ORDER_NO,\n" +
                "   ORDER_TYPE_CD,\n" +
                "   SHOP_ID,\n" +
                "   SHOP_NAME,\n" +
                "   CUSTOM_ORDER_NO,\n" +
                "   CUSTOM_NAME,\n" +
                "   CUSTOM_MAKE_SHIRT,\n" +
                "   TRANSIT_GROUP,\n" +
                "   COUNTRY,\n" +
                "   SLEEVE_FLAG,\n" +
                "   CUSTOMER_ID,\n" +
                "   CUSTOMER_NAME,\n" +
                "   FACTORY_ID,\n" +
                "   STYLE_ID,\n" +
                "   REF_ORDER_ID,\n" +
                "   SPECIAL_ORDER,\n" +
                "   TRYON_ORDER,\n" +
                "   FIT_STYLE_SIZE,\n" +
                "   TAILOR_ID,\n" +
                "   SHIPPING_DESTINATION,\n" +
                "   ORDER_DATE,\n" +
                "   PAYMENT_DATE,\n" +
                "   PAYMENT_CONFIRM_DATE,\n" +
                "   ORDER_ACCEPT_DATE,\n" +
                "   ORDER_PRO_START_DATE,\n" +
                "   ORDER_PRO_END_DATE,\n" +
                "   ORDER_PACK_DATE,\n" +
                "   ORDER_SHIPMENTS_DATE,\n" +
                "   TARGET_DATE,\n" +
                "   REAL_DATE,\n" +
                "   ORDER_STATUS_CD,\n" +
                "   ORDER_PRODUCE_STATUS_CD,\n" +
                "   ORDER_QC34,\n" +
                "   ORDER_QC35,\n" +
                "   ORDER_QC36,\n" +
                "   ORDER_QC37,\n" +
                "   ORDER_NUMBER,\n" +
                "   ORDER_MATERIAL_COST,\n" +
                "   ORDER_DESIGN_COST,\n" +
                "   ORDER_PROCESS_COST,\n" +
                "   ORDER_PACK_COST,\n" +
                "   ORDER_EXPRESS_COST,\n" +
                "   ORDER_SELL_ACCOUNT,\n" +
                "   ORDER_OTHER_COST,\n" +
                "   URGENT_CD,\n" +
                "   MATERIAL_SOURCE,\n" +
                "   REMARKS,\n" +
                "   DELETE_FLAG,\n" +
                "   VERSION,\n" +
                "   CREATE_DATE,\n" +
                "   UPDATE_DATE,\n" +
                "   CREATE_USER,\n" +
                "   UPDATE_USER,\n" +
                "   SEL_KBN,\n" +
                "   PRINT_FLAG \n" +
                ")\n" +
                "VALUES\n" +
                "   (\n" +
                "       '" + this.ORDER_NO + "',\n" +
                "       '" + this.ORDER_TYPE_CD + "',\n" +
                "       '" + this.SHOP_ID + "',\n" +
                "       '" + this.SHOP_NAME + "',\n" +
                "       '" + ValueUtil.StringNullValue(this.CUSTOM_ORDER_NO) + "',\n" +
                "       '" + this.CUSTOM_NAME + "',\n" +
                "       '" + this.CUSTOM_MAKE_SHIRT + "',\n" +
                "       '" + ValueUtil.StringNullValue(this.TRANSIT_GROUP) + "',\n" +
                "       '" + ValueUtil.StringNullValue(this.COUNTRY) + "',\n" +
                "       '" + this.SLEEVE_FLAG + "',\n" +
                "       '" + this.CUSTOMER_ID + "',\n" +
                "       '" + this.CUSTOMER_NAME + "',\n" +
                "       '" + ValueUtil.StringNullValue(this.FACTORY_ID) + "',\n" +
                "       '" + aliyunMaxStyleId + "',\n" +
                "       '" + this.REF_ORDER_ID + "',\n" +
                "       '" + ValueUtil.StringNullValue(this.SPECIAL_ORDER) + "',\n" +
                "       '" + this.TRYON_ORDER + "',\n" +
                "       '" + this.FIT_STYLE_SIZE + "',\n" +
                "       '" + this.TAILOR_ID + "',\n" +
                "       '" + this.SHIPPING_DESTINATION + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.PAYMENT_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.PAYMENT_CONFIRM_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_ACCEPT_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_PRO_START_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_PRO_END_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_PACK_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.ORDER_SHIPMENTS_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.TARGET_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.REAL_DATE) + "',\n" +
                "   '" + this.ORDER_STATUS_CD + "',\n" +
                "   '" + ValueUtil.StringNullValue(this.ORDER_PRODUCE_STATUS_CD) + "',\n" +
                "   '" + ValueUtil.StringNullValue(this.ORDER_QC34) + "',\n" +
                "   '" + ValueUtil.StringNullValue(this.ORDER_QC35) + "',\n" +
                "   '" + ValueUtil.StringNullValue(this.ORDER_QC36) + "',\n" +
                "   '" + ValueUtil.StringNullValue(this.ORDER_QC37) + "',\n" +
                "   '" + this.ORDER_NUMBER + "',\n" +
                "   '" + this.ORDER_MATERIAL_COST + "',\n" +
                "   '" + this.ORDER_DESIGN_COST + "',\n" +
                "   '" + this.ORDER_PROCESS_COST + "',\n" +
                "   '" + this.ORDER_PACK_COST + "',\n" +
                "   '" + this.ORDER_EXPRESS_COST + "',\n" +
                "   '" + this.ORDER_SELL_ACCOUNT + "',\n" +
                "   '" + this.ORDER_OTHER_COST + "',\n" +
                "   '" + this.URGENT_CD + "',\n" +
                "   '" + this.MATERIAL_SOURCE + "',\n" +
                "   '" + this.REMARKS + "',\n" +
                "   '" + this.DELETE_FLAG + "',\n" +
                "   '" + this.VERSION + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.CREATE_DATE) + "',\n" +
                "   '" + DateTimeUtil.convertToDate(this.UPDATE_DATE) + "',\n" +
                "   '" + this.CREATE_USER + "',\n" +
                "   '" + this.UPDATE_USER + "',\n" +
                "   '" + this.SEL_KBN + "',\n" +
                "   '" + this.PRINT_FLAG + "' \n" +
                "   );";

    }

    public void buildPrepareData() {
        this.ORDER_PRODUCE_STATUS_CD = "PRODUCTION_STATUS-PRO_00";
        this.ORDER_QC34 = "QUALITY_STATUS-QC_00";
        this.ORDER_QC35 = "QUALITY_STATUS-QC_00";
        this.ORDER_QC36 = "QUALITY_STATUS-QC_00";
        this.ORDER_QC37 = "QUALITY_STATUS-QC_00";
        this.ORDER_STATUS_CD = "ORDER_STATUS-OS_20";
    }
}
